package com.heyue.ems.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.heyue.common.log.annotation.Log;
import com.heyue.common.log.enums.BusinessType;
import com.heyue.common.security.annotation.PreAuthorize;
import com.heyue.ems.domain.Gps;
import com.heyue.ems.service.IGpsService;
import com.heyue.common.core.web.controller.BaseController;
import com.heyue.common.core.web.domain.AjaxResult;
import com.heyue.common.core.utils.poi.ExcelUtil;
import com.heyue.common.core.web.page.TableDataInfo;

/**
 * GPS监控设备（基础）Controller
 * 
 * @author WCHU
 * @date 2021-07-26
 */
@RestController
@RequestMapping("/gps")
public class GpsController extends BaseController
{
    @Autowired
    private IGpsService gpsService;

    /**
     * 查询GPS监控设备（基础）列表
     */
    @PreAuthorize(hasPermi = "ems:gps:list")
    @GetMapping("/list")
    public TableDataInfo list(Gps gps)
    {
        startPage();
        List<Gps> list = gpsService.selectGpsList(gps);
        return getDataTable(list);
    }

    /**
     * 导出GPS监控设备（基础）列表
     */
    @PreAuthorize(hasPermi = "ems:gps:export")
    @Log(title = "GPS监控设备（基础）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gps gps) throws IOException
    {
        List<Gps> list = gpsService.selectGpsList(gps);
        ExcelUtil<Gps> util = new ExcelUtil<Gps>(Gps.class);
        util.exportExcel(response, list, "GPS监控设备（基础）数据");
    }

    /**
     * 获取GPS监控设备（基础）详细信息
     */
    @PreAuthorize(hasPermi = "ems:gps:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gpsService.selectGpsById(id));
    }

    /**
     * 新增GPS监控设备（基础）
     */
    @PreAuthorize(hasPermi = "ems:gps:add")
    @Log(title = "GPS监控设备（基础）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gps gps)
    {
        return toAjax(gpsService.insertGps(gps));
    }

    /**
     * 修改GPS监控设备（基础）
     */
    @PreAuthorize(hasPermi = "ems:gps:edit")
    @Log(title = "GPS监控设备（基础）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gps gps)
    {
        return toAjax(gpsService.updateGps(gps));
    }

    /**
     * 删除GPS监控设备（基础）
     */
    @PreAuthorize(hasPermi = "ems:gps:remove")
    @Log(title = "GPS监控设备（基础）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gpsService.deleteGpsByIds(ids));
    }
}
